<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        #personalPage {
            width: 75%;
            height: 50%;
            margin: 5px auto;
        }

        h2 {
            text-align: center;
            font-size: 32px;
        }

        label {
            font-size: 24px;
        }

        p {
            display: inline-block;
            font-size: 24px;
        }
    </style>
    <link href="https://www.layuicdn.com/layui-v2.5.6/css/layui.css" rel="stylesheet" type="text/css"/>
    <!-- 引入layui js -->
    <script src="https://www.layuicdn.com/layui-v2.5.6/layui.js"></script>
</head>
<body>
<div id="personalPage">
    <h2>我的个人信息</h2>
    <hr color="#ccc">
    <label>我的姓名:</label>
    <p id="myName"></p><br>
    <hr color="#ccc">
    <label>我的性别:</label>
    <p id="myGender"></p><br>
    <hr color="#ccc">
    <label>我的班级:</label>
    <p id="myClass"></p><br>
    <hr color="#ccc">
    <label>我的学号:</label>
    <p id="myStuid"></p><br>
    <hr color="#ccc">
    <label>我的分数:</label>
    <p id="myScore"></p><br>
    <hr color="#ccc">
    <button class="layui-btn layui-btn-normal" id="ChangePwd" onclick="changePassword('ChangePassword.html')">修改登录密码
    </button>
</div>
</body>
<script>
    let userinfo;
    $.ajax({
        url: '/user/userStatus',
        method: "get",
        async: false,
        success: (data) => {
            userinfo = data;
        },
    })
    console.log(userinfo);
    let myName = document.getElementById("myName");
    let myGender = document.getElementById("myGender");
    let myClass = document.getElementById("myClass");
    let myStuid = document.getElementById("myStuid");
    let myScore = document.getElementById("myScore");
    if (userinfo.userType === '1') {
        $.ajax({
            url: '/teacher/getTeacher',
            method: 'GET',
            data: {"stuid": userinfo.userId},
            success: (result) => {
                console.log(result);
                myName.innerText = result.name;
                myClass.innerText = null;
                myStuid.innerText = result.teacherID;
                myGender.innerText = result.gender;
                myScore.innerText = null;
            }
        });
    } else {
        $.ajax({
            url: '/student/getStudent',
            method: 'GET',
            data: {"stuid": userinfo.userId},
            success: (result) => {
                console.log(result);
                myName.innerText = result.data.name;
                myClass.innerText = result.data.classes;
                myStuid.innerText = result.data.stuid;
                myGender.innerText = result.data.gender;
                myScore.innerText = result.data.score;
            }
        })
    }
    let passwordIsAltered = false;

    function isAltered(bool) {
        passwordIsAltered = bool;
    }

    function changePassword(url) {
        layer.open({
            type: 2,
            title: '修改密码',
            shadeClose: false,
            shade: false,
            maxmin: false, //关闭最大化最小化按钮
            fixed: true,
            area: ['1440px', '810px'],
            content: url,
            end: function () {
                if (passwordIsAltered) {
                    window.location.href = '/';
                }
            }
        });
    }
</script>
</html>